<template>
	<view class="content fofa poRel">
		<tabnav title="我的企业联系人" :col="back"></tabnav>
		<view style="height: 40rpx;"></view>
		<view class="wid90 mar bacFFF borRad20 box1" style="padding: 10rpx 0;">
			<view class="wid90 mar">
				<view style="height: 20rpx;"></view>
				<view class="foSi25" style="color: #6E6E6E;">证件类型</view>
				<picker @change="bindPickerChange" :value="idtype" :range="xuanze">
					<view class="hei80 dis disAl disJuB foSi30">
						<view>{{xuanze[idtype]}}</view>
						<uni-icons size="25" type="right"></uni-icons>
					</view>
				</picker>
			</view>
			<view class="xia"></view>
			<view class="wid90 mar">
				<view style="height: 20rpx;"></view>
				<view class="foSi25" style="color: #6E6E6E;">姓名</view>
				<view class="hei80 dis disAl disJuB foSi30">
					<input class="wid100" v-model="name" placeholder="请输入姓名"/>
				</view>
			</view>
			<view class="xia"></view>
			<view class="wid90 mar">
				<view style="height: 20rpx;"></view>
				<view class="foSi25" style="color: #6E6E6E;">证件号</view>
				<view class="hei80 dis disAl disJuB foSi30">
					<input class="wid100" v-model="idnum" placeholder="请输入证件号（选填）"/>
				</view>
			</view>
			<view class="xia"></view>
			<view class="wid90 mar">
				<view style="height: 20rpx;"></view>
				<view class="foSi25" style="color: #6E6E6E;">手机号</view>
				<view class="hei80 dis disAl disJuB foSi30">
					<input class="wid100" v-model="mobile" placeholder="请输入手机号"/>
				</view>
			</view>
		</view>
		<view class="wid100 poAbs bacFFF dis disAl disJuC" style="height: 125rpx;bottom: 0;">
			<view class="hei80 dis disAl disJuC coFFF borRad10" @click="baocun"
				style="width: 400rpx;" :style="{'background-color':back}">确认并保存</view>
		</view>
	</view>
</template>

<script>
	import tabnav from "../common/tabnav/tabnav.vue"
	export default {
		components: {
			tabnav,
		},
		data() {
			return {
				back: uni.getStorageSync('back'),
				xuanze: ['居民身份证','港澳台居民居住证','港澳居民来往内地通行证'],
				idtype: 0,
				name: '',
				idnum: '',
				mobile: '',
				id: ''
			}
		},
		onLoad(option) {
			if(option.list){
				var list = JSON.parse(option.list)
				this.id = list.id
				this.idtype = parseInt(list.idtype)-1
				this.idnum = list.idnum
				this.mobile = list.mobile
				this.name = list.name
			}
		},
		methods: {
			baocun(){
				if(!this.name){
					uni.showToast({
						title: '请输入姓名',
						icon: 'error'
					})
					return
				}
				if(!this.mobile){
					uni.showToast({
						title: '请输入手机号',
						icon: 'error'
					})
					return
				}
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_person_add',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {
						type: 1,
						idtype: parseInt(that.idtype)+1,
						name: that.name,
						mobile: that.mobile,
						idnum: that.idnum,
						id: that.id
					},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							uni.navigateBack({delta: 1})
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.idtype = e.detail.value
			},
			tiaozhuan(url){
				uni.redirectTo({
					url: url
				});
			},
		}
	}
</script>

<style>
	.content {
		height: 100vh;
		background-color: #F4F3F3;
	}
	.foSi28{
		font-size: 28rpx;
	}
	.xia{
		height: 1rpx;
		background: #BBBBBB;
	}
</style>
